package com.ruoyi.busi.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.busi.domain.bo.BusiCompanyQuotaBo;
import com.ruoyi.busi.domain.vo.BusiCompanyQuotaVo;
import com.ruoyi.busi.service.IBusiCompanyQuotaService;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 企业配额Controller
 *
 * @author ruoyi
 * @date 2024-11-24
 */
@Validated
@Api(value = "企业配额控制器", tags = {"企业配额管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/busi/companyQuota")
public class BusiCompanyQuotaController extends BaseController {

    private final IBusiCompanyQuotaService iBusiCompanyQuotaService;

    /**
     * 查询企业配额列表
     */
    @ApiOperation("查询企业配额列表")
    @PreAuthorize("@ss.hasPermi('busi:companyQuota:list')")
    @GetMapping("/list")
    public TableDataInfo<BusiCompanyQuotaVo> list(@Validated(QueryGroup.class) BusiCompanyQuotaBo bo) {
        return iBusiCompanyQuotaService.queryPageList(bo);
    }

    /**
     * 导出企业配额列表
     */
    @ApiOperation("导出企业配额列表")
    @PreAuthorize("@ss.hasPermi('busi:companyQuota:export')")
    @Log(title = "企业配额", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated BusiCompanyQuotaBo bo, HttpServletResponse response) {
        List<BusiCompanyQuotaVo> list = iBusiCompanyQuotaService.queryList(bo);
        ExcelUtil.exportExcel(list, "企业配额", BusiCompanyQuotaVo.class, response);
    }

    /**
     * 获取企业配额详细信息
     */
    @ApiOperation("获取企业配额详细信息")
    @PreAuthorize("@ss.hasPermi('busi:companyQuota:query')")
    @GetMapping("/{id}")
    public AjaxResult<BusiCompanyQuotaVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iBusiCompanyQuotaService.queryById(id));
    }

    /**
     * 新增企业配额
     */
    @ApiOperation("新增企业配额")
    @PreAuthorize("@ss.hasPermi('busi:companyQuota:add')")
    @Log(title = "企业配额", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody BusiCompanyQuotaBo bo) {
        return toAjax(iBusiCompanyQuotaService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改企业配额
     */
    @ApiOperation("修改企业配额")
    @PreAuthorize("@ss.hasPermi('busi:companyQuota:edit')")
    @Log(title = "企业配额", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody BusiCompanyQuotaBo bo) {
        return toAjax(iBusiCompanyQuotaService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除企业配额
     */
    @ApiOperation("删除企业配额")
    @PreAuthorize("@ss.hasPermi('busi:companyQuota:remove')")
    @Log(title = "企业配额" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iBusiCompanyQuotaService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
